<template>
    <view class="page-box">
        <header class="header"></header>
        <view class="section">
            <view class="h2" v-if="list.length > 0">{{class_name}}</view>
            <view class="list column" v-if="list.length > 0">
                <view class="box" v-for="(item,index) in list" :key="index">
                    <a class="title" :href="item.url" @click="addKnowledgeArticleClick(index)">{{item.title}}</a>
                    <a class="desc" :href="item.url" @click="addKnowledgeArticleClick(index)">{{item.des}}</a>
                    <view class="bottom row bothSide verCenter">
                        <view class="time">{{item.time}}</view>
                        <view class="row verCenter">
                            <text class="iconfont icon-liulanliang" style="margin-left: 24rpx;"></text>
                            <text class="num">{{item.view_click}}</text>
                        </view>
                    </view>
                </view>
            </view>
            <view class="no-data column rowCenter verCenter" v-else>
                <image src="@/static/clue.23025e4e.png" class="pic" mode="aspectFill"></image>
                <text class="tt">暂无新闻栏目哦～</text>
            </view>
        </view>
    </view>
</template>

<script>
    import { API } from '@/util/api.js';

    export default {
        data() {
            return {
                class_id: '',
                class_name: '',
                list: [],
                shareData: {
                    title: '',
                    desc: '',
                    link: '',
                    imgUrl: ''
                }
            };
        },
        onLoad(options) {
            this.class_id = options.class_id;
            this.class_name = options.class_name;
            //更换标题
            if (this.class_name) {
                uni.setNavigationBarTitle({
                    title: this.class_name
                })
            }
        },
        mounted() {

        },
        onShow() {
            this.getData();
        },
        methods: {
            getData() {
                this.request(API.getKnowledgeArticles, 'GET', { class_id: this.class_id }, true).then(res => {
                    if (res.code === 0) {
                        this.list = res.data;
                    }
                });
            },
            /**
             * 获取知识星球文章点击量
             */
            addKnowledgeArticleClick(article_order) {
                this.request(API.addKnowledgeArticleClick, 'POST', { class_id: this.class_id, article_order: Number(article_order) + 1 }, false).then(res => {

                })
            }
        }
    };
</script>

<style scoped lang="scss">
    @import '@/assets/css/index/news.scss';
</style>